﻿using System;

namespace susiunitypackage.susi.util.Runtime.tookit {
    /// <summary>
    /// 监听器
    /// Obsolete <see cref="Observer.Creat"/>
    /// </summary>
    [Obsolete("using Observer.XXX instead")]
    public class Observer<T> : IObserver<T> ,IDisposable{
        public event Action            OnCompletedEvent;
        public event Action<Exception> OnErrorEvent;
        public event Action<T>         OnNextEvent;

        public void OnCompleted()
        {
            OnCompletedEvent?.Invoke();
        }

        public void OnError(Exception error)
        {
            OnErrorEvent?.Invoke(error);
        }

        public void OnNext(T value)
        {
            OnNextEvent?.Invoke(value);
        }

        public void Dispose()
        {
            OnCompletedEvent = null;
            OnErrorEvent     = null;
            OnNextEvent      = null;
        }
    }
}